package com.lmx.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.UserService;
import com.lmx.repoDomain.tmodel.business.User;//huibati

@Controller
@RequestMapping("/backStand")
public class UserController {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	UserService<User> userService;

	// 启用禁用
	@RequestMapping(value = "/updateUserStatus", method = RequestMethod.GET)
	@ResponseBody
	public String updateUserStatus(String userID, String markStatus) {
		String json = "";
		Map<String, Object> msgMap = new HashMap<String, Object>();
		User user = new User();
		// 验证userID
		if (userID != null && !userID.isEmpty()) {// 如果用户id不为null，修改用户状态
			if (!String.valueOf(userID).isEmpty()) {
				user.setId(Long.valueOf(userID));
			} else {
				msgMap.put("flag", 0);
				json = CommonUtil.mapToJsonString(msgMap);
				return json;
			}

			// 验证markStatus
			if (markStatus != null && !markStatus.isEmpty()) {
				user.setStatus(Short.parseShort(markStatus));
			} else {
				msgMap.put("flag", 0);
				json = CommonUtil.mapToJsonString(msgMap);
				return json;
			}
			// 修改用户状态
			userService.updateUserStatus(user);
		}
		msgMap.put("flag", 1);
		json = CommonUtil.mapToJsonString(msgMap);
		return json;
	}

}
